package com.yanqu.road.server.manager.activity.seacraftsouthsea;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.CrossActivityDetail;
import com.yanqu.road.entity.activity.seacraft.SeacraftSouthSeaCrossUserInfo;
import com.yanqu.road.entity.activity.seacraft.SeacraftSouthSeaLockPatronsInfo;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaActivityConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaShipConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.entity.rank.yrank.UnionYRank;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.cmd.activity.autoreward.rank.SeacraftSouthSeaActivityRank;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.CrossGeneralActivityRankMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;
import com.yanqu.road.server.manager.yrank.CrossYRankMgr;
import com.yanqu.road.server.manger.SeacraftSouthSeaCommonMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 海上争霸之南海丝路
 * @Author cwq
 * @Data 2022/1/20 15:38
 */
public class SeacraftSouthSeaMgr extends TempMgr {

    public static Map<Integer, SeacraftSouthSeaActivityGroup> activityGroupMap = new ConcurrentHashMap<>();

    public static Random random = new Random();

    @Override
    public boolean init() throws Exception {
        reload();
        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        SeacraftSouthSeaConfigMgr.reloadConfig();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        getLogger().info("start reload Seacraft SouthSea activity  start");
        String nowTimeStr = DateHelper.getCurrentDateTimeString();
        List<Integer> activityTypeList = new ArrayList<>();
        activityTypeList.add(eActivityType.SeacraftActivity.getValue());
        Map<Integer, ActivityInfo> activityInfoMap = ActivityBussiness.getOpenCrossRankActivityInfoMapByCrossServerId(activityTypeList, nowTimeStr, CrossBaseServer.getInstance().getServerId());
        for (ActivityInfo activityInfo : activityInfoMap.values()) {
            Map<Integer, UnionActivityGroup> groupMap = Cross2UnionActivityGroupMgr.getGroupMap(activityInfo.getActivityId());
            if (groupMap != null) {
                for (int groupId : groupMap.keySet()) {
                    getSeacraftSouthSeaActivity(activityInfo.getActivityId(), groupId, true);
                }
            }
        }
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    @Override
    public boolean save() {
        List<Integer> removeIds = new ArrayList<>();
        for (SeacraftSouthSeaActivityGroup item : activityGroupMap.values()) {
            item.save();
            ActivityInfo activityInfo = ActivityMgr.getActivityInfo(item.getActivityId());
            if (null == activityInfo) {
                activityInfo = ActivityMgr.getActivityInfoMayLoadDB(item.getActivityId());
            }
            if (activityInfo == null || !ActivityMgr.activityInShowTime(activityInfo)) {
                removeIds.add(item.getActivityId());
            }
        }

        for (Integer activityId : removeIds) {
            activityGroupMap.remove(activityId);
            getLogger().info("海上争霸释放过期活动{}", activityId);
        }
        return true;
    }

    /**
     * @param activityId
     * @param newIfNull
     * @return
     */
    public static synchronized SeacraftSouthSeaActivity getSeacraftSouthSeaActivity(int activityId, int groupId, boolean newIfNull) {
        SeacraftSouthSeaActivityGroup southSeaActivityGroup = activityGroupMap.get(activityId);
        if (null == southSeaActivityGroup) {
            synchronized (activityGroupMap) {
                southSeaActivityGroup = activityGroupMap.get(activityId);
                if (null == southSeaActivityGroup) {
                    ActivityInfo activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
                    if (activityInfo == null) {
                        return null;
                    }
                    southSeaActivityGroup = new SeacraftSouthSeaActivityGroup(activityId);
                    activityGroupMap.put(activityId, southSeaActivityGroup);
                }
            }
        }
        SeacraftSouthSeaActivity southSeaActivity = southSeaActivityGroup.getActivity(groupId, newIfNull);
        if (null != southSeaActivity){
            ActivityInfo activityInfo = ActivityMgr.getActivityInfo(southSeaActivity.getActivityId());
            if (null == activityInfo){ //重载会被覆盖,所以要重复读取
                activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
            }
        }
        return southSeaActivity;
    }

    /**
     * @param activityId
     * @return
     */
    public static SeacraftSouthSeaActivity getSeacraftSouthSeaActivity(int activityId, int groupId) {
        return getSeacraftSouthSeaActivity(activityId, groupId, true);
    }


    /**
     * 海盗之乱下发 锁定晋级名额
     *
     * @param activityId
     * @param unionList
     */
    public static boolean lockPromotionUnion(int activityId, int groupId, List<String> unionList) {
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            getLogger().info("收到海盗之乱的竞猜名单,，但是活动不存在 activityId：{},unionList:{}", activityId, StringUtils.listToString(unionList, ","));
            return false;
        }
        synchronized (southSeaActivity) {
            int curRound = southSeaActivity.getCurRound();
            if (curRound >= 1) {
                lockPromotionUnion(activityId, groupId, unionList, 1);
            }
        }
        return true;
    }

    /**
     * 锁定晋级南海丝路 的名额
     *
     * @param activityId
     * @param unionList
     */
    public static void lockPromotionUnion(int activityId, int groupId, List<String> unionList, int round) {
        getLogger().info("锁定晋级 南海丝路 的联盟名额 round:{}, activityId：{}，unionList:{}", round, activityId, StringUtils.listToString(unionList, ","));
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId, true);
        southSeaActivity.lockPromotionUnion(activityId, unionList, round);
    }

    /**
     * 同步锁定联盟的联盟成员给跨服
     *
     * @param activityId
     * @param unionList
     */
    public static void synPromotionUnion(int activityId, int groupId, List<SeacraftSouthSeaProto.SeacraftSouthSeaUnionInfo> unionList, List<SeacraftSouthSeaProto.SeacraftSouthSeaLockUserInfo> userTeamInfoList) {
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId, true);
        synchronized (southSeaActivity) {
            southSeaActivity.synPromotionUnion(unionList);
            southSeaActivity.synUserTeamInfo(userTeamInfoList);
        }
    }

    /**
     * 锁定晋级联盟
     */
    public static synchronized void lockPromotionUnionTask() {
        for (SeacraftSouthSeaActivityGroup group : activityGroupMap.values()) {
            // 当前定时器执行到轮次
            int curRound = group.getCurRound();
            if (curRound <= 1) {
                // 第一轮的晋级 走海上之乱那边
                continue;
            }
            for (SeacraftSouthSeaActivity southSeaActivity : group.getActivityList()) {
                synchronized (southSeaActivity) {
                    CrossActivityDetail crossActivityDetail = ActivityMgr.getCrossActivityDetail(southSeaActivity.getActivityId(), southSeaActivity.getGroupId(), true);
                    int round = (int) (crossActivityDetail.getParam1() + 1);
                    for (int i = round; i <= curRound; i++) {
                        // 排序
                        List<String> promotionList = southSeaActivity.refreshAllPromotionShip();
                        // 锁定完 同步给各个区服
                        lockPromotionUnion(group.getActivityId(), southSeaActivity.getGroupId(), promotionList, i);
                    }
                }
            }

        }
    }

    /**
     * 第一阶段一开始就 向区服索要 联盟数据 和联盟成员的门客数据
     */
    public static synchronized void synUnionInfoTask() {
        for (SeacraftSouthSeaActivityGroup group : activityGroupMap.values()) {
            // 当前定时器执行到轮次
            for (SeacraftSouthSeaActivity southSeaActivity : group.getActivityList()) {
                synchronized (southSeaActivity) {
                    southSeaActivity.synUnionInfo();
                }
            }
        }
    }

    /**
     * 索要晋级的联盟数据
     *
     * @param activityId
     */
    public static void getPromotionUnion(int activityId, int groupId, long serverId) {
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            return;
        }
        if (southSeaActivity.getCurRound() <= 0) {
            return;
        }
        synchronized (southSeaActivity) {
            SeacraftSouthSeaProto.SeacraftSouthSeaSynPromotionUnionCrossToGameMsg.Builder crossToGameMsg = southSeaActivity.getPromotionUnion();
            if (crossToGameMsg.getPromotionListList().size() > 0) {
                MessageHelper.sendPacket(serverId, 0, YanQuMessageUtils.buildMessage(GameProtocol.S_SEACRAFT_SOUTH_SEA_LOCK_JOIN_UNION_FROM_CROSS, crossToGameMsg));
            }
        }
    }

    /**
     * 抵达任务
     */
    public static void arrivalTask() {
        for (SeacraftSouthSeaActivityGroup group : activityGroupMap.values()) {
            for (SeacraftSouthSeaActivity southSeaActivity : group.getActivityList()) {
                synchronized (southSeaActivity) {
                    southSeaActivity.arrivalTask();
                }
            }
        }
    }


    /**
     * 获取玩家数据
     *
     * @param activityId
     * @param userId
     * @param serverId
     * @param unionId
     */
    public static void getUserData(int activityId, long userId, long serverId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            return;
        }
        synchronized (southSeaActivity) {
            builder.setUserInfo(southSeaActivity.getSeacraftSouthSeaUserInfo(userId,unionId,serverId));
            CrossActivityDetail crossActivityDetail = ActivityMgr.getCrossActivityDetail(activityId, groupId, true);
            List<String> list = southSeaActivity.getPromotionMap().get((int) crossActivityDetail.getParam1());
            if (list != null) {
                builder.addAllUnionIdList(list);
            }
            builder.addAllResultList(southSeaActivity.getSeacraftSouthSeaResultList(unionId));
            SeacraftSouthSeaProto.SeacraftSouthSeaShipInfo.Builder shipInfo = southSeaActivity.getUnionShip(userId);
            if (shipInfo != null) {
                builder.setUnionShip(shipInfo);
            }
        }
        MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(ClientProtocol.U_SEACRAFT_SOUTH_SEA_GET_USER_DATA, builder));
    }

    /**
     * 查看捐献的船只
     *
     * @param activityId
     * @param userId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipRespMsg.Builder getDonationShip(int activityId, long userId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getUnionDonationShipList(userId, unionId);
        }
    }


    /**
     * 捐献
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipCrossToGameMsg.Builder donationShip(long userId, long serverId, int activityId, String unionId, int propId, int num, String consume) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipCrossToGameMsg.newBuilder();
        builder.setConsume(consume);
        SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            stcMsg.setRet(GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN);
            builder.setStcMsg(stcMsg);
            return builder;
        }
        synchronized (southSeaActivity) {
            stcMsg = southSeaActivity.donationShip(userId, serverId, unionId, propId, num);
        }
        builder.setStcMsg(stcMsg);
        return builder;
    }

    /**
     * 查看 联盟的捐献 详情
     *
     * @param activityId
     * @param type       部件
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipDetailRespMsg.Builder getDonationShipDetail(int activityId, long userId, String unionId, int type) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipDetailRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetDonationShipDetailRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getDonationShipDetail(userId, unionId, type);
        }
    }

    /**
     * 进入南海丝路
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaEnterRespMsg.Builder southSeaEnter(int activityId, long userId, long refreshTime,String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaEnterRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaEnterRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.southSeaEnter(userId, refreshTime, unionId);
        }
    }

    /**
     * 离开系统
     *
     * @param activityId
     * @param userId
     */
    public static void exit(int activityId, long userId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity != null) {
            southSeaActivity.exit(userId);
        }
    }


    /**
     * 查看船只详情
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetShipRecordRespMsg.Builder getShipRecord(int activityId, String unionId, int type) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetShipRecordRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetShipRecordRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getShipRecord(unionId, type);
        }
    }

    /**
     * @param activityId
     * @param type          操作类型 0 进攻 1突袭 2使用道具进攻 3修复 5 使用船桨
     * @param userId
     * @param serverId
     * @param ownUnionId    玩家的unionId
     * @param targetUnionId 要攻击的联盟id  type 0 2 才需要传
     * @param dispatchType  派遣的小队类型  type = 0,1 才需要传
     * @param titleId
     * @param count         使用道具的数量  type = 2 3 4 才有
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaActionCrossToGameMsg.Builder action(int activityId, int type, long userId, long serverId, String ownUnionId, String targetUnionId, int dispatchType, int titleId, int count, long preReduceCount,int propId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaActionCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaActionCrossToGameMsg.newBuilder();
        builder.setType(type);
        builder.setCount(preReduceCount);
        builder.setPropId(propId);
        SeacraftSouthSeaProto.SeacraftSouthSeaActionRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaActionRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            stcMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            builder.setStcMsg(stcMsg);
            return builder;
        }
        synchronized (southSeaActivity) {
            stcMsg = southSeaActivity.action(type, userId, serverId, ownUnionId, targetUnionId, titleId, dispatchType, count, preReduceCount, propId);
            if (stcMsg.getRet() == 0 && (type == 0 || type == 1)) {
                // 下发小队的门客
                SeacraftSouthSeaCrossUserInfo userInfo = southSeaActivity.getUserInfoMap().get(userId);
                if (userInfo != null && userInfo.getChallengeData() != null) {
                    for (SeacraftSouthSeaLockPatronsInfo item : userInfo.getChallengeData().getPatronsInfoList()) {
                        builder.addPatronsId(item.getId());
                    }
                }
            }
        }
        builder.setStcMsg(stcMsg);
        return builder;
    }

    /**
     * 购买buff
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffCrossToGameMsg.Builder buyBuff(int activityId, long userId, int preReduceCount, int buffId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffCrossToGameMsg.newBuilder();
        builder.setPreReduceCount(preReduceCount);
        SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            stcMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            builder.setStcMsg(stcMsg);
            return builder;
        }
        synchronized (southSeaActivity) {
            stcMsg = southSeaActivity.buyBuff(userId, buffId, preReduceCount);
        }
        builder.setStcMsg(stcMsg);
        return builder;
    }

    /**
     * 挑战
     *
     * @param activityId
     * @param userId
     * @param targetId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaChallengeCrossToGameMsg.Builder challenge(int activityId, long userId, long targetId, int type, int blood, int buffId, long goldNum) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaChallengeCrossToGameMsg.Builder crossToGameMsg = SeacraftSouthSeaProto.SeacraftSouthSeaChallengeCrossToGameMsg.newBuilder();
        crossToGameMsg.setGoldNum(goldNum);
        crossToGameMsg.setType(type);
        SeacraftSouthSeaProto.SeacraftSouthSeaChallengeRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaChallengeRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            stcMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            crossToGameMsg.setStcMsg(stcMsg);
            return crossToGameMsg;
        }
        synchronized (southSeaActivity) {
            stcMsg = southSeaActivity.challenge(userId, targetId, type, blood, buffId, goldNum);
        }
        crossToGameMsg.setStcMsg(stcMsg);
        return crossToGameMsg;
    }


    /**
     * 获取挑战数据
     *
     * @param activityId
     * @param userId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetChallengeRespMsg.Builder getChallenge(int activityId, long userId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetChallengeRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetChallengeRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getChallengeInfo(userId);
        }
    }

    /**
     * 领取连胜奖励
     *
     * @param activityId
     * @param userId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaReceiveWinStreakRewardRespMsg.Builder receiveWinStreakReward(int activityId, long userId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveWinStreakRewardRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveWinStreakRewardRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.receiveWinStreakReward(userId);
        }
    }

    /**
     * 领取竞猜奖励
     *
     * @param activityId
     * @param userId
     * @param round
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaReceiveGuessRewardCrossToGameMsg.Builder receiveGuessReward(int activityId, long userId, int round) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveGuessRewardCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveGuessRewardCrossToGameMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.receiveGuessReward(userId, round);
        }
    }

    /**
     * 进入竞猜
     *
     * @param activityId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaEnterGuessRespMsg.Builder enterGuess(int activityId, int groupId) {
        SeacraftSouthSeaProto.SeacraftSouthSeaEnterGuessRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaEnterGuessRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.enterGuess();
        }
    }

    /**
     * 竞猜
     *
     * @param userId
     * @param round
     * @param unionList
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGuessRespMsg.Builder guess(int activityId, long userId, long serverId, String ownUnionId, int round, List<String> unionList) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGuessRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGuessRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        int curRound = southSeaActivity.getCurRound();
        if (curRound != round) {
            // 不能竞猜该轮数据
            builder.setRet(GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_THE_ROUND_GUESS_NO_OPEN);
            return builder;
        }
        if(DateHelper.getCurrentSecond() >= getRoundStartTime(activityId, curRound)){
            // 不能竞猜该轮数据
            builder.setRet(GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_THE_ROUND_GUESS_NO_OPEN);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.guess(userId, ownUnionId, serverId, round, unionList);
        }
    }

    /**
     * 查看竞猜成功的玩家
     *
     * @param activityId
     * @param round
     * @param guessNum
     * @param num
     * @param pageNum
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetGuessSuccessUserRespMsg.Builder getGuessSuccessUser(int activityId, int round, int guessNum, int num, int pageNum, int groupId) {
        SeacraftSouthSeaProto.SeacraftSouthSeaGetGuessSuccessUserRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetGuessSuccessUserRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getGuessSuccessUser(round, guessNum, num, pageNum);
        }
    }

    /**
     * 查看联盟排名
     *
     * @param activityId
     * @param userId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankRespMsg.Builder getUnionRank(int activityId, long userId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getUnionRank(userId, unionId);
        }
    }


    /**
     * 查看联盟排名列表
     *
     * @param activityId
     * @param userId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankListRespMsg.Builder getUnionRankList(int activityId, long userId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankListRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetUnionRankListRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getUnionRankList(userId, unionId);
        }
    }


    /**
     * 领取排行榜奖励
     *
     * @param activityId
     * @param userId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.Builder receiveUnionRank(int activityId, long userId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.receiveUnionRank(userId);
        }
    }

    /**
     * 查看抵达信息
     *
     * @param activityId
     * @param unionId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetArrivalInfoRespMsg.Builder getArrivalInfo(int activityId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetArrivalInfoRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetArrivalInfoRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getArrivalInfo(unionId);
        }
    }

    /**
     * @param activityId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetFixRankRespMsg.Builder getFixRank(int activityId, String unionId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetFixRankRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetFixRankRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getFixRank(unionId);
        }
    }

    /**
     * 查看船只攻防信息
     *
     * @param activityId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetBattleRecordRespMsg.Builder getBattleRecord(int activityId, String unionId, int type) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetBattleRecordRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetBattleRecordRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getBattleRecord(unionId, type);
        }
    }


    /**
     * 查看船只成员详细攻防数据
     *
     * @param activityId
     * @param type
     * @param unionId
     * @param sonType
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetMemberBattleDetailRespMsg.Builder getMemberBattleDetail(int activityId, int type, String unionId, int sonType, String targetId) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetMemberBattleDetailRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetMemberBattleDetailRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getMemberBattleDetail(type, unionId, sonType, targetId);
        }
    }


    /**
     * 请求功勋酒馆数据
     * @param activityId
     * @param userId
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaPubRespMsg.Builder getPub(int activityId, long userId){
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaPubRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaPubRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            return southSeaActivity.getPub(userId);
        }
    }

    /**
     * 功勋酒馆挖宝
     * @param activityId
     * @param userId
     * @param id
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubCrossToGameMsg.Builder openPub(int activityId, long userId, int floor, int id, String preConsume){
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubCrossToGameMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubCrossToGameMsg.newBuilder();
        SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubRespMsg.newBuilder();
        builder.setPreConsume(preConsume);
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            stcMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            builder.setStcMsg(stcMsg);
            return builder;
        }
        synchronized (southSeaActivity) {
            stcMsg = southSeaActivity.openPub(userId, floor, id - 1);
            builder.setStcMsg(stcMsg);
        }
        return builder;
    }


    /**
     * 查看联盟加速榜
     * @param activityId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRecordRespMsg.Builder getSpeedUpRecord(int activityId, String unionId){
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRecordRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRecordRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            List<SeacraftSouthSeaProto.SeacraftSouthSeaSpeedUpRecordInfo> recordInfoList = southSeaActivity.getSpeedUpRecord(unionId);
            builder.addAllRecordList(recordInfoList);
        }
        builder.setRet(0);
        return builder;
    }

    /**
     * 获取当前船只加速详情
     * @param activityId
     * @param unionId
     * @return
     */
    public static SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRespMsg.Builder getCurSpeedUpDetail(int activityId, String unionId){
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRespMsg.Builder builder = SeacraftSouthSeaProto.SeacraftSouthSeaGetSpeedUpRespMsg.newBuilder();
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return builder;
        }
        synchronized (southSeaActivity) {
            List<SeacraftSouthSeaProto.SeacraftSouthSeaSpeedUpInfo> list = southSeaActivity.getCurSpeedUpDetail(unionId);
            builder.addAllSpeedUpList(list);
        }
        builder.setRet(0);
        return builder;
    }


    /**
     * 玩家 进出联盟
     *
     * @param type
     * @param activityId
     * @param userId
     * @param unionId
     */
    public static void changeUnion(int type, int activityId, long userId, String unionId, UnionProto.UnionBaseTempMsg unionBaseTempMsg) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionId);
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            return;
        }
        SeacraftSouthSeaActivityConfig activityConfig = SeacraftSouthSeaConfigMgr.getConfigMap().get(activityId);
        if (activityConfig == null) {
            return;
        }
        ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
        synchronized (southSeaActivity) {
            if (type == 1) {
                // 修改联盟信息
                SeacraftSouthSeaUnionInfo unionInfo = southSeaActivity.getUnionInfo(unionId, false);
                if (unionInfo != null) {
                    unionInfo.getUnionData().setUnionBaseInfo(UnionBasePb.parseUnionBaseInfo(unionBaseTempMsg));
                    unionInfo.getUnionData().setUpdateOption();
                }
            } else if (type == 2) {
                // 加入联盟
                if(!ActivityHelper.activityInTime(activityInfo)){
                    return;
                }
                int now = DateHelper.getCurrentSecond();
                if(activityInfo.getBeginTime() <= now && now < activityInfo.getBeginTime() + activityConfig.pretimeList.get(1)){
                    southSeaActivity.joinUnion(userId, unionId);
                }
            } else if(type == 3) {
                // 退出商会 TODO 热更需要临时写
                int now = DateHelper.getCurrentSecond();
                if (activityInfo.getBeginTime() <= now && now < activityInfo.getBeginTime() + activityConfig.pretimeList.get(1)) {
                    SeacraftSouthSeaCrossUserInfo userInfo = southSeaActivity.getUserInfoMap().get(userId);
                    if (userInfo == null || StringUtils.isNullOrEmpty(userInfo.getBaseData().getUnionId())) {
                        return;
                    }
                    // 移除原来操作
                    SeacraftSouthSeaUnionInfo oldUnionInfo = southSeaActivity.getUnionInfo(userInfo.getBaseData().getUnionId(), false);
                    if (oldUnionInfo != null && oldUnionInfo.getMemberMap().containsKey(userId)) {
                        oldUnionInfo.getMemberMap().remove(userId);
                        // 扣除 已经捐献数据
                        for (Map.Entry<Integer, Long> entry : userInfo.getBaseData().getDonationShipMap().entrySet()) {
                            oldUnionInfo.addDonationShip(entry.getKey(), -entry.getValue(), now);
                        }
                        oldUnionInfo.getUnionData().setUpdateOption();
                    }
                    userInfo.getBaseData().setUnionId("");
                }
            }
        }
    }

    /**
     * 同步玩家数据
     *
     * @param activityId
     * @param userPatronsInfoList
     */
    public static void synUserInfo(int activityId, int groupId, List<SeacraftSouthSeaProto.SeacraftSouthSeaSynUserPatronsInfo> userPatronsInfoList) {
        SeacraftSouthSeaActivity southSeaActivity = getSeacraftSouthSeaActivity(activityId, groupId);
        if (southSeaActivity == null) {
            return;
        }
        synchronized (southSeaActivity) {
            southSeaActivity.synUserInfo(userPatronsInfoList);
        }
    }

    /**
     * 自动补发联盟奖励
     *
     * @param activityId
     */
    @Deprecated
    public static AutoSendRewardProto.CrossUnionRankWithUnionInfoMsg.Builder autoSendUnionRankList(int activityId) {
        SeacraftSouthSeaActivityRank crossRank = new SeacraftSouthSeaActivityRank(activityId);
        return crossRank.sendCrossUnionWithUnionInfoRank();
    }

    /**
     * 获取船只对应的配置
     *
     * @param unionInfo
     * @return
     */
    public static SeacraftSouthSeaShipConfig getShipConfig(SeacraftSouthSeaUnionInfo unionInfo) {
        SeacraftSouthSeaShipConfig shipConfig = null;
        SeacraftSouthSeaActivityConfig activityConfig = SeacraftSouthSeaConfigMgr.getConfigMap().get(unionInfo.getUnionData().getActivityId());
        for (SeacraftSouthSeaShipConfig item : activityConfig.getShipList()) {
            for (int i = 0; i < activityConfig.donateList.size(); i++) {
                long value = unionInfo.getUnionData().getDonationShipMap().getOrDefault(i, 0L);
                if (value < item.getExp()) {
                    return item;
                }
            }
            shipConfig = item;
        }
        return shipConfig;
    }

    /**
     * 获取本轮 比赛的开始时间 ms
     *
     * @param activityId
     * @param round
     * @return
     */
    public static long getRoundStartTime(int activityId, int round) {
        SeacraftSouthSeaActivityConfig activityConfig = SeacraftSouthSeaConfigMgr.getConfigMap().get(activityId);
        if (activityConfig == null) {
            return 0;
        }
        ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
        if (activityInfo == null) {
            return 0;
        }
        if (round > activityConfig.roundTimeList.size()) {
            return 0;
        }
        Integer[] config = activityConfig.roundTimeList.get(round - 1);
        // 活动开始时间
        return (activityInfo.getBeginTime() + config[0]) * DateHelper.SECOND_MILLIONS;
    }

    /**
     * 获取本轮 比赛的结束时间 ms
     *
     * @param activityId
     * @param round
     * @return
     */
    public static long getRoundEndTime(int activityId, int round) {
        SeacraftSouthSeaActivityConfig activityConfig = SeacraftSouthSeaConfigMgr.getConfigMap().get(activityId);
        ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
        if (round > activityConfig.roundTimeList.size()) {
            return 0;
        }
        Integer[] config = activityConfig.roundTimeList.get(round - 1);
        // 活动结束时间
        return (activityInfo.getBeginTime() + config[1]) * DateHelper.SECOND_MILLIONS;
    }

    /**
     * 是否在比赛时间中
     *
     * @return
     */
    public static boolean inRoundTime(int activityId, int round, long now) {
        long roundStartTime = SeacraftSouthSeaMgr.getRoundStartTime(activityId, round);
        if (now < roundStartTime || roundStartTime == 0) {
            // 比赛还未开始
            return false;
        }
        long roundEndTime = SeacraftSouthSeaMgr.getRoundEndTime(activityId, round);
        if (now >= roundEndTime) {
            // 比赛结束
            return false;
        }
        return true;
    }


    /**
     * 锁定海盗之乱第二阶段名单
     */
    public static synchronized void fixSeacraftPirateRiotUnionList() {
        for (Integer activityId : activityGroupMap.keySet()) {
            SeacraftSouthSeaActivityGroup group = activityGroupMap.get(activityId);
            if (null == group) {
                continue;
            }
            for (SeacraftSouthSeaActivity southSeaActivity : group.getActivityList()) {
                // 是否已锁定一阶段名单
                CrossActivityDetail activityDetail = ActivityMgr.getCrossActivityDetail(activityId, southSeaActivity.getGroupId(), true);
                if (activityDetail.getParam1() >= 1) {
                    continue;
                }
                // 获取活动和配置
                SeacraftSouthSeaActivityConfig config = SeacraftSouthSeaConfigMgr.getConfigMap().get(activityId);
                ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
                if (config == null || activityInfo == null) {
                    continue;
                }
                // 获取一些数据
                if (config.roundTimeList.isEmpty() || config.roundTimeList.get(0).length < 3) {
                    getLogger().error("");
                    continue;
                }
                // 还没到
                long fixTime = activityInfo.getBeginTime() + config.haiDaoEndTime + DateHelper.MINUTE_SECONDS * 5;
                if (fixTime > System.currentTimeMillis() / 1000) {
                    continue;
                }
                // 获取排名
                int count = config.roundTimeList.get(0)[2];
                List<String> unionList = new ArrayList<>();
                List<UnionYRank> rankList = CrossYRankMgr.getSortUnionRankList(activityId, southSeaActivity.getGroupId(), String.valueOf(eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue()));
                int rank = 0;
                for (UnionYRank unionRank : rankList) {
                    if (unionRank.getValue().compareTo(BigInteger.ZERO) == 0) {
                        continue;
                    }
                    rank++;
                    unionList.add(unionRank.getUnionUid());
                    if (rank >= count) {
                        break;
                    }
                }
                // 锁定名单
                lockPromotionUnion(activityId, southSeaActivity.getGroupId(), unionList);
            }
        }
    }


}
